package secret.santa.server;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import secret.santa.client.CS_User;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class DB_User
{	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
	private String encodedKey;
	
	@Persistent
    private String username;
    
    @Persistent
    private String password;
	
	@Persistent
	private String fullName;
	
	@Persistent
	private String partner;
	
	@Persistent
	private String email;

	public CS_User toClient()
	{
		CS_User c = new CS_User();
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		
		
		c.encodedKey = encodedKey;
		c.username = username;
		c.password = password;
		c.fullName = fullName;
		if(partner != null)
			c.partner = pm.getObjectById(DB_User.class, partner).getFullName();
		else
			c.partner = new String("");
		c.email = email;
		
		pm.close();
		
		return c;
	}
	/**
	 * @param encodedKey the encodedKey to set
	 */
	public void setEncodedKey(String encodedKey) {
		this.encodedKey = encodedKey;
	}

	/**
	 * @return the encodedKey
	 */
	public String getEncodedKey() {
		return encodedKey;
	}

	/**
	 * @param username the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param fullName the fullName to set
	 */
	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	/**
	 * @return the fullName
	 */
	public String getFullName() {
		return fullName;
	}

	/**
	 * @param partner the partner to set
	 */
	public void setPartner(String partner) {
		this.partner = partner;
	}

	/**
	 * @return the partner
	 */
	public String getPartner() {
		return partner;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}
}
